import request from '@/utils/request'

export const getusersAPI = ({ page, size }) => request({ // 获取 ---- 员工列表
  url: '/sys/user',
  method: 'GET',
  params: {
    page,
    size
  }
})

export const removeuserAPI = (id) => request({ // 删除 ---- 员工
  url: `/sys/user/${id}`,
  method: 'DELETE'
})

export const adduserAPI = ({ username, mobile, formOfEmployment, workNumber, departmentName, timeOfEntry, correctionTime }) => request({
  url: '/sys/user',
  method: 'POST',
  data: {
    username,
    mobile,
    formOfEmployment,
    workNumber,
    departmentName,
    timeOfEntry,
    correctionTime
  }
})

// data = [  { username, mobile, workNumber, timeOfEntry, correctionTime } ]
export const userbatchAPI = (data) => request({ // 员工批量导入
  url: '/sys/user/batch',
  method: 'POST',
  data: data
})

export const getuserAPI = (id) => request({ // 获取-员工-基本信息
  url: `/sys/user/${id}`,
  method: 'GET'
})

// { staffPhoto, id, mobile, username, password, timeOfEntry, workNumber, correctionTime, departmentName, roleIds, companyId, companyName}
export const setuserAPI = (data) => request({
  url: `/sys/user/${data.id}`,
  method: 'PUT',
  data
}) // 更新员工基本资料

export const personalInfoAPI = (id) => request({ // 获取员工个人信息
  url: `/employees/${id}/personalInfo`,
  method: 'GET'
})

/** *
 *  更新用户详情的基础信息
 * **/
export function updatePersonal(data) {
  return request({
    url: `/employees/${data.userId}/personalInfo`,
    method: 'put',
    data
  })
}

/** **
 * 获取用户的岗位信息
 *
 * ****/
export function getJobDetail(id) {
  return request({
    url: `/employees/${id}/jobs`
  })
}

/**
 * 保存岗位信息
 * ****/
export function updateJob(data) {
  return request({
    url: `/employees/${data.userId}/jobs`,
    method: 'put',
    data
  })
}

export const getsimpleAPI = () => request({
  url: '/sys/user/simple',
  method: 'GET'
})

export const assignRolesAPI = ({ id, roleIds }) => request({ // 角色权限分配
  url: '/sys/user/assignRoles',
  method: 'PUT',
  data: {
    id,
    roleIds
  }
})
